<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
class IndexController extends CommonController {
    public function index(){
    	$menu = S('menu');
    	$tmp = array();
    	foreach ($menu as $k => $v) {
    		if($v['ismenu']==1){
    			$tmp[$k]=$v;
    		}
    	}
      $arr = genTree5($tmp);
    	if(in_array(UID, C('ADMIN_ID'))){
    		$arr = genTree5($tmp);
    	}else{
    		$auth = new \Think\Auth();
    		// 用户权限ID
    		$rule = $auth->getGroups(UID);
    		$str ='';
    		foreach ($rule as  $v) {
    			$str.=$v['rules'].',';
    		}
    		$b = explode(',',rtrim($str,','));
    		$c = array_unique($b);
    		$tree = array();
    		foreach ($tmp as $k => $v) {
    			if(in_array($k, $c)){
    				$v['show']=1;
    				$tree[$k] = $v;
    			}
    		}
    		$arr = genTree5($tree);
    	}
    	$this->assign('menu',$arr);
    	$this->display();
    }


    // 更新所有缓存
   public function upAllCache()
   {
   	$str = '';
   	switch (true) {
   		case !R('Auth/ruleCache'):
   			$str = '权限控制节点';
   			break;
   	}
   	if($str) $this->error('更新'.$str.'缓存失败',U('Goods/index'));
   	$this->success('更新成功',U('Goods/index'));
   }
}